# set(<variable> <value>... CACHE <type> <docstring> [FORCE])
if(CMAKE_SYSTEM_NAME MATCHES "Windows")  # 判断平台
    set(OPENCV_PATH "D:/Opencv/opencv_455/build" CACHE PATH "OpenCV Library Path.")
    set(OPENCV_SO_LOC "${OPENCV_PATH}/x64/vc15/bin")
    #    file(GLOB OPENCV_LIBS "${OPENCV_PATH}/x64/vc15/lib/*.lib")
    set(OPENCV_LIBS "${OPENCV_PATH}/x64/vc15/lib/opencv_world455$<$<CONFIG:Debug>:d>.lib")
#    if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
#        set(OPENCV_LIBS "${OPENCV_PATH}/x64/vc15/lib/opencv_world455d.lib")
#    else()
#        set(OPENCV_LIBS "${OPENCV_PATH}/x64/vc15/lib/opencv_world455.lib")
#    endif()

else() #(CMAKE_SYSTEM_NAME MATCHES "Linux")
    set(OPENCV_PATH "OpenCV" CACHE PATH "OpenCV Library Path.")
    set(OPENCV_SO_LOC "${OPENCV_PATH}/lib")
    set(OPENCV_LIBS "")
endif()

set(OPENCV_INCLUDE "${OPENCV_PATH}/include")
#message("${OPENCV_INCLUDE}")
#message("${OPENCV_SO_LOC}")
#message("${OPENCV_LIBS}")


# 导入外部库的语法
#add_library(<name>
#    <SHARED|STATIC|MODULE|OBJECT|UNKNOWN> IMPORTED
#    [GLOBAL])
add_library(OpenCV INTERFACE)

add_library(OpenCV::OpenCV ALIAS OpenCV)  # 起个别名， 防止混淆

#set_property(TARGET OpenCV PROPERTY
#             IMPORTED_LOCATION "${OPENCV_SO_LOC}")
#set_property(TARGET OpenCV PROPERTY
#             IMPORTED_IMPLIB  "${OPENCV_LIBS}")

target_include_directories(OpenCV INTERFACE "${OPENCV_INCLUDE}")  # 导入的库只能是 INTERFACE
target_link_libraries(OpenCV INTERFACE "${OPENCV_LIBS}")  # 导入的库只能是 INTERFACE
#get_target_property(VGOT OpenCV INTERFACE_INCLUDE_DIRECTORIES)
#message("VGOT ${VGOT}")
#get_target_property(VGOT OpenCV INTERFACE_LINK_DIRECTORIES)
#message("VGOT ${VGOT}")
#get_target_property(VGOT OpenCV INTERFACE_LINK_LIBRARIES)
#message("VGOT ${VGOT}")
